﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CourseArraging.Properties; 

namespace CourseArraging.Frm.jygl
{
    /// <summary>
    /// 版权所有
    /// 石世特@温州医学院 sst330381@gmail.com
    /// </summary> 
    public partial class FrmTecCondi2 : Form
    {
        #region 属性
        public List<string> courselist = new List<string>();
        public List<string> gradelist = new List<string>();
        protected YhxxService.YhxxServiceClient yhxxdao = new YhxxService.YhxxServiceClient();

        private string tec_time;

        public delegate void SearchResultEventHandler(DataTable dt);
        public event SearchResultEventHandler SearchResultEvent;
        #endregion

        #region 构造器
        private static FrmTecCondi2 Instance;
        private FrmTecCondi2(string time)
        {
            InitializeComponent();
            this.tec_time = time;
        }
        public static FrmTecCondi2 GetInstance(string time)
        {
            //if (Instance == null || Instance.IsDisposed)
            //{
            //    Instance = new FrmTecCondi2(time);
            //}

            Instance = new FrmTecCondi2(time);
            Instance.BringToFront();
            return Instance;
        }
        #endregion

        #region 事件
        private void tsb_ok_Click(object sender, EventArgs e)
        {
            this.GetConditions();
            DataTable dt = this.yhxxdao.GetTecinfo(
                        this.txt_no.Text.Trim(), this.txt_spell.Text.Trim(), this.combo_sex.Text,
                        this.ucCombo_dep2.comboBox1.Text, this.courselist.ToArray(), this.gradelist.ToArray(), this.tec_time);
            if (SearchResultEvent != null)
                this.SearchResultEvent(dt);
            this.Close();
        }

        private void tsb_exit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        #endregion

        #region 方法
        public void GetConditions()
        {
            this.courselist.Clear();
            this.gradelist.Clear();
            foreach (CheckBox box in this.groupBox_course.Controls.OfType<CheckBox>())
            {
                if (box.Checked)
                {
                    this.courselist.Add(box.Text);
                }
            }
            foreach (CheckBox box2 in this.groupBox_grade.Controls.OfType<CheckBox>())
            {
                if (box2.Checked)
                {
                    this.gradelist.Add(box2.Text);
                }
            }
        }
        #endregion
    }
}
